﻿using System;
using Medianamik.Core;
using Medianamik.UI.Web.MVP.View;

namespace Medianamik.UI.Web.MVP.Presentation
{
    public abstract class ModulePresenter<TView>  : IModulePresenter<TView> where TView : IModuleView
    {
        protected BreadcrumbBuilder BreadcrumbBuilder { get; set; }

        protected ModulePresenter(TView view)
        {
            View = view;
            View.Initialize += Initialize;
            BreadcrumbBuilder = new BreadcrumbBuilder();
        }

        protected virtual void Initialize(object sender, EventArgs e)
        {
            if(!View.IsPostBack)
            {
                BindBreadcrumbTrail();
            }
        }

        public TView View
        {
            get;
            private set;
        }

        protected virtual void BindBreadcrumbTrail()
        {
            BreadcrumbBuilder.AppendRawUrl(View.RawUrl, true);
            View.BreadcrumbTrail = BreadcrumbBuilder.ToString();
        }
    }
}